package hikvision.service.impl;


import com.hikvision.exception.LoginException;

import hikvision.mapper.UserMapper;
import hikvision.pojo.dto.LoginParam;
import hikvision.pojo.entity.User;
import hikvision.pojo.vo.LoginVo;
import hikvision.service.UserService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @ClassName StudentImpl
 * @Description TODO
 * @Author dongpengchao
 * @Date 2022/2/16 10:35
 * @Version 1.0
 */
@Service
public class UserImpl implements UserService {
    @Resource
    private UserMapper userMapper;

    @Override
    public LoginVo login(LoginParam req) {
         User loginUser = new User();
         loginUser.setName(req.getName());
         loginUser.setPwd(req.getPwd());
         User exist = userMapper.getUserInfo(loginUser);
        if (exist == null) {
            throw new LoginException(">>> login error, wrong username/pwd");
        }
        final LoginVo result = new LoginVo();
        result.setId(exist.getId());
        result.setName(exist.getName());
        return result;
    }
}
